x=int(input()) 

a=x%10 #5 
 
a1=x//10 #173 
 
a2=a1%10 #3  
 
a3=a1//10 #17 
 
a4=a3%10 #7 
 
a5=a3//10 #1 
 
k=a4*100+a2*10+a  
 
k1=a5*100+a2*10+a 
 
 
k2=a5*100+a2*10+a 
 
k3=a5*100+a4*10+a 
 
k4=a5*100+a4*10+a2 
 
k5=a2*10+a 
 
k6=a4*10+a 
 
k7=a4*10+a2 
 
k8=a5*10+a 
 
k9=a5*10+a2 
 
k10=a5*10+a4 
 
 
 
z=x  
max_prostoe=0 
 
count=0 
if len(str(x))==4 or x<0:
  print("0")
else:
  for i in range(1,z+1): 
    if z%i==0: 
      count+=1 
  if count==2: 
    if max_prostoe<z: 
        max_prostoe=z  
     
     
  z=a  
  count=0  
  for i in range(1,z+1): 
    if z%i==0: 
      count+=1 
  if count==2: 
    if max_prostoe<z: 
        max_prostoe=z  
     
  z=a2  
  count=0  
  for i in range(1,z+1): 
    if z%i==0: 
      count+=1 
  if count==2: 
    if max_prostoe<z: 
        max_prostoe=z 
     
  z=a3  
  count=0  
  for i in range(1,z+1): 
    if z%i==0: 
      count+=1 
  if count==2: 
      if max_prostoe<z: 
          max_prostoe=z 
     
  z=a4 
  count=0  
  for i in range(1,z+1): 
    if z%i==0: 
      count+=1 
  if count==2: 
      if max_prostoe<z: 
          max_prostoe=z 
     
  z=a5  
  count=0  
  for i in range(1,z+1): 
    if z%i==0: 
      count+=1 
  if count==2: 
      if max_prostoe<z: 
          max_prostoe=z 
     
  z=k10  
  count=0  
  for i in range(1,z+1): 
    if z%i==0: 
      count+=1 
  if count==2: 
        if max_prostoe<z: 
          max_prostoe=z 
     
  z=k9  
  count=0  
  for i in range(1,z+1): 
    if z%i==0: 
      count+=1 
  if count==2: 
        if max_prostoe<z: 
            max_prostoe=z 
     
  z=k8  
  count=0  
  for i in range(1,z+1): 
    if z%i==0: 
      count+=1 
  if count==2: 
      if max_prostoe<z: 
          max_prostoe=z 
     
  z=k9  
  count=0  
  for i in range(1,z+1): 
    if z%i==0: 
      count+=1 
  if count==2: 
      if max_prostoe<z: 
          max_prostoe=z 
     
  z=k8 
  count=0  
  for i in range(1,z+1): 
    if z%i==0: 
      count+=1 
  if count==2: 
      if max_prostoe<z: 
          max_prostoe=z   
  z=k7  
  count=0  
  for i in range(1,z+1): 
    if z%i==0: 
      count+=1 
  if count==2: 
      if max_prostoe<z: 
          max_prostoe=z 
     
  z=k6 
  count=0  
  for i in range(1,z+1): 
    if z%i==0: 
      count+=1 
  if count==2: 
      if max_prostoe<z: 
          max_prostoe=z 
     
  z=k5  
  count=0  
  for i in range(1,z+1): 
    if z%i==0: 
      count+=1 
  if count==2: 
      if max_prostoe<z: 
          max_prostoe=z 
     
  z=k4  
  count=0  
  for i in range(1,z+1): 
    if z%i==0: 
      count+=1 
  if count==2: 
      if max_prostoe<z: 
          max_prostoe=z 
     
  z=k3  
  count=0  
  for i in range(1,z+1): 
    if z%i==0: 
      count+=1 
  if count==2: 
      if max_prostoe<z: 
          max_prostoe=z 
     
  z=k2  
  count=0  
  for i in range(1,z+1): 
    if z%i==0: 
      count+=1 
  if count==2: 
      if max_prostoe<z: 
          max_prostoe=z   
  z=k1  
  count=0  
  for i in range(1,z+1): 
    if z%i==0: 
      count+=1 
  if count==2: 
      if max_prostoe<z: 
          max_prostoe=z 
     
  z=k  
  count=0  
  for i in range(1,z+1): 
    if z%i==0: 
      count+=1 
  if count==2: 
      if max_prostoe<z: 
          max_prostoe=z 
  print(max_prostoe)
